<template>
    <div>
        <!-- 编辑弹出框 -->
        <el-dialog v-model="dialogFormVisible2" title="Shipping address">
            <el-form :model="editData" label-width="100px">
                <el-form-item label="医务账号" prop="account">
                    <el-input v-model="editData.data.account" />
                </el-form-item>
                <el-form-item label="权限" prop="purvew">
                    <el-select v-model="editData.data.purview" placeholder="Please select a zone">
                        <el-option label="医生" value="医生" />
                        <el-option label="护士" value="护士" />
                        <el-option label="医务管理员" value="医务管理员" />
                        <el-option label="实习助理" value="实习助理" />
                        <el-option label="药房" value="药房" />
                    </el-select>
                </el-form-item>
                <el-form-item label="账号密码" prop="password">
                    <el-input v-model="editData.data.password" />
                </el-form-item>
                <el-form-item label="身份证号" prop="idcard">
                    <el-input v-model="editData.data.idcard" />
                </el-form-item>
                <el-form-item label="手机号" prop="phone">
                    <el-input v-model="editData.data.phone" />
                </el-form-item>
                <el-form-item label="性别" prop="sex">
                    <el-input v-model="editData.data.sex" />
                </el-form-item>
                <el-form-item prop="head">
                    <img :src="editData.data.headurl" alt="" class="imgggg">
                </el-form-item>
            </el-form>
            <template #footer>
                <span class="dialog-footer">
                    <el-button type="primary" @click="changeEdit">
                        确定编辑
                    </el-button>
                    <el-button @click="dialogFormVisible2 = false">取消编辑</el-button>
                </span>
            </template>
        </el-dialog>
    </div>
</template>

<script setup lang="ts">
import {ref,reactive, watchEffect} from 'vue'
import {  usersEdit, usersGetbyid } from '@/API/user.api';
import { ElMessage,  } from 'element-plus'

const emit = defineEmits(['getdatalist'])

const props = defineProps({
    data:{
        type:Object,
        defalut:()=>{}
    }
})

/**编辑弹出框 */
const dialogFormVisible2 = ref(false)
// 编辑弹出框数据
const editData = reactive({
    data: {
        account: '',
        password: '',
        id: null,
        sex: '',
        idcard: '',
        purview: '',
        phone: '',
        headurl: ''
    }
})
async function show(){
    dialogFormVisible2.value = true
    let res = await usersGetbyid({ id: props.data.id})
    let data = res.data.data[0]
    console.log(res.data.data[0]);
    // 给编辑弹出框数据赋值
    editData.data = data
}
// 点击编辑弹出确认编辑按钮
async function changeEdit() {
    let res = await usersEdit(editData.data)
    dialogFormVisible2.value = false
    if(res.data.code === 1){
        ElMessage({
            type: 'success',
            message: res.data.msg,
        })
    }else{
        ElMessage({
            type: 'info',
            message: res.data.msg,
        })
    }

    emit('getdatalist','')
}
watchEffect(()=>{
    show()
})
</script>

<style scoped lang="scss">
// 弹出框照片
.imgggg {
    width: 160px;
    height: 160px;
}
</style>